package com.cpi.cornpp.transitcorn.services;

import java.util.ArrayList;
import java.util.List;

import com.cpi.cornpp.common.exception.CornPPException;
import com.cpi.cornpp.transitcorn.converter.TransitCornConverter;
import com.cpi.cornpp.transitcorn.dao.TransitCornDAO;
import com.cpi.cornpp.transitcorn.exception.TransitCornException;

/**
 * Transit Corn Service
 * @author Edgar Joao
 *
 */
public class TransitCornService {

	/**
	 * @author Edgar Joao
	 * @return Transit Corn List
	 * @throws TransitCornException
	 */
	public List list(int id) throws TransitCornException{
		TransitCornDAO transitCornDAO = null;
		TransitCornConverter transitCornConverter = null;
		
		List transitCornDTO = null;
		List transitCornView = null;
		
		try {
			
			transitCornDAO = new TransitCornDAO();
			transitCornConverter = new TransitCornConverter();			
			
			transitCornDTO = new ArrayList(0);
			transitCornView = new ArrayList(0);

			transitCornDTO = transitCornDAO.list(id);
			transitCornView = transitCornConverter.convertDTOs(transitCornDTO);						
			
		} catch (TransitCornException transitCornException) {
			transitCornException.printStackTrace(System.out);
			transitCornException= new TransitCornException(transitCornException, CornPPException.LAYER_SERVICE,CornPPException.ACTION_LISTS);
			throw transitCornException;
		}catch (Exception e){
			TransitCornException transitCornException = null;
			e.printStackTrace(System.out);
			transitCornException = new TransitCornException(e , CornPPException.LAYER_SERVICE,CornPPException.ACTION_LISTS);
			throw transitCornException;
		}			
			
		return transitCornView;
	}
}
